<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>函数练习</title>
</head>
<style>
    body {
        width: 100vw;
        height: 100vh;
    }
</style>
<body>
<button id="btn">展示当前点击时间</button>
</body>
<script>
    (function () {
        //点击处理
        function handleClick(clcikParam, clickCallBack) {
            if (typeof clickCallBack != 'function') {
                throw new Error('clickCallBack must be a function')
            }
            clickCallBack(clcikParam)
        }

        //逻辑回调
        function callBack({date,ele}) {
            ele.innerHTML=date.toLocaleString()
        }

        //绑定事件
        const btn = document.querySelector('#btn')
        btn.addEventListener('click',(e)=>{
            handleClick({date: new Date(), ele: e.target},callBack)
        })
        btn.click()
    })()
</script>
</html>